home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolf3dmacsource.sit / Wolf3DMacSource / SetupScalersPPC.c < prev    next >
C/C++ Source or Header  |  1994-10-19  |  5KB  |  272 lines

  1. #include "WolfDef.h"
  2. #include <string.h>
  3. #include "SoundMusicSystem.h"
  4. #include "mixedmode.h"
  5.  
  6. Word ScaleDiv[2048];            /* Divide table for scalers */
  7.  
  8. /**********************************
  9.  
  10.     Create the compiled scalers
  11.  
  12. **********************************/
  13.  
  14. Boolean SetupScalers(void)
  15. {
  16.     Word i;
  17.     
  18.     if (!ScaleDiv[1]) {        /* Divide table inited already? */
  19.         i = 1;
  20.         do {
  21.             ScaleDiv[i] = 0x40000000/i;        /* Get the recipocal for the scaler */
  22.         } while (++i<2048);
  23.     }
  24.     MaxScaler = 2048;        /* Init the highest scaler value */
  25.     return TRUE;            /* No errors possible */
  26. }
  27.  
  28. /**********************************
  29.  
  30.     Release the memory from the scalers
  31.  
  32. **********************************/
  33.  
  34. void ReleaseScalers(void)
  35. {
  36. }
  37.  
  38. /**********************************
  39.  
  40.     Draw a vertical line with a scaler
  41.     (Used for WALL drawing)
  42.     This is now in assembly language
  43.     
  44. **********************************/
  45.  
  46. /* void ScaleGlue(void *a,t_compscale *b,void *c); */
  47. void ScaleGlue(void *a,Word b,void *c,Word d,Word e,Word f,Word g);
  48. /*
  49. ; R3 = ArtPtr
  50. ; R4 = Maxlines
  51. ; R5 = ScreenPtr
  52. ; R6 = Frac
  53. ; R7 = Integer
  54. ; R8 = VideoWidth
  55. ; R9 = Delta
  56. */
  57.  
  58. #if 0
  59. void IO_ScaleWallColumn(Word x,Word scale,LongWord column)
  60. {
  61.     Word TheFrac;
  62.     Word TheInt;
  63.     Word y;
  64.     Byte *ArtStart;
  65.     
  66.     if (scale) {        /* Uhh.. Don't bother */
  67.         scale*=2;
  68.         TheFrac = 0x80000000UL / scale;
  69.  
  70.         ArtStart = &ArtData[(column>>7)&0x3f][(column&127)<<7];
  71.         if (scale<VIEWHEIGHT) {
  72.             y = (VIEWHEIGHT-scale)/2;
  73.             TheInt = TheFrac>>24;
  74.             TheFrac <<= 8;
  75.             ScaleGlue(ArtStart,scale,
  76.                 &VideoPointer[(y*VideoWidth)+x],
  77.                 TheFrac,
  78.                 TheInt,
  79.                 VideoWidth,
  80.                 0
  81.             );
  82.             return;
  83.         }
  84.         y = (scale-VIEWHEIGHT)/2;        /* How manu lines to remove */
  85.         y = y*TheFrac;
  86.         TheInt = TheFrac>>24;
  87.         TheFrac <<= 8;
  88.         ScaleGlue(&ArtStart[y>>24],VIEWHEIGHT,
  89.             &VideoPointer[x],
  90.             TheFrac,
  91.             TheInt,
  92.             VideoWidth,
  93.             y<<8
  94.         );
  95.     }
  96. }
  97. #endif
  98. /**********************************
  99.  
  100.     Draw a vertical line with a masked scaler
  101.     (Used for SPRITE drawing)
  102.     
  103. **********************************/
  104.  
  105. typedef struct {
  106.     unsigned short Topy;
  107.     unsigned short Boty;
  108.     unsigned short Shape;
  109. } SpriteRun;
  110.  
  111. void SpriteGlue(Byte *a,Word b,Word c,Byte *d,Word e,Word f);
  112. /*
  113. SGArtStart    EQU    R3        ;Pointer to the 6 byte run structure
  114. SGFrac    EQU    R4        ;Pointer to the scaler
  115. SGInteger    EQU R5        ;Pointer to the video
  116. SGScreenPtr    EQU    R6        ;Pointer to the run base address
  117. SGCount    EQU R7
  118. SGDelta    EQU    R8
  119. */
  120.  
  121. void IO_ScaleMaskedColumn(Word x,Word scale,unsigned short *CharPtr,Word column) 
  122. {
  123.     Byte * CharPtr2;
  124.     int Y1,Y2;
  125.     Byte *Screenad;
  126.     SpriteRun *RunPtr;
  127.     Word TheFrac;
  128.     Word TFrac;
  129.     Word TInt;
  130.     Word RunCount;
  131.     int TopY;
  132.     Word Index;
  133.     Word Delta;
  134.     
  135.     if (!scale) {
  136.         return;
  137.     }
  138.     CharPtr2 = (Byte *) CharPtr;
  139.     TheFrac = ScaleDiv[scale];        /* Get the scale fraction */ 
  140.     RunPtr = (SpriteRun *) &CharPtr[CharPtr[column+1]/2];    /* Get the offset to the RunPtr data */
  141.     Screenad = &VideoPointer[x];        /* Set the base screen address */
  142.     TFrac = TheFrac<<8;
  143.     TInt = TheFrac>>24;
  144.     TopY = (VIEWHEIGHT/2)-scale;        /* Number of pixels for 128 pixel shape */
  145.  
  146.     while (RunPtr->Topy != (unsigned short) -1) {        /* Not end of record? */
  147.         Y1 = scale*(LongWord)RunPtr->Topy/128+TopY;
  148.         if (Y1<(int)VIEWHEIGHT) {        /* Clip top? */
  149.         Y2 = scale*(LongWord)RunPtr->Boty/128+TopY;
  150.         if (Y2>0) {
  151.         
  152.         if (Y2>(int)VIEWHEIGHT) {
  153.             Y2 = VIEWHEIGHT;
  154.         }
  155.         Index = RunPtr->Shape+(RunPtr->Topy/2);
  156.         Delta = 0;
  157.         if (Y1<0) {
  158.             Delta = (0-(Word)Y1)*TheFrac;
  159.             Index += (Delta>>24);
  160.             Delta <<= 8;
  161.             Y1 = 0;
  162.         }
  163.         RunCount = Y2-Y1;
  164.         if (RunCount) {
  165.             SpriteGlue(
  166.             &CharPtr2[Index],    /* Pointer to art data */
  167.             TFrac,                /* Fractional value */ 
  168.             TInt,                /* Integer value */
  169.             &Screenad[Y1*VideoWidth],            /* Pointer to screen */
  170.             RunCount,            /* Number of lines to draw */
  171.             Delta                    /* Delta value */
  172.             );
  173.         }
  174.         }
  175.         } 
  176.         RunPtr++;                        /* Next record */
  177.     }    
  178. }
  179.  
  180. /**********************************
  181.  
  182.     Draw an automap tile
  183.     
  184. **********************************/
  185.  
  186. Byte *SmallFontPtr;
  187.  
  188. void DrawSmall(Word x,Word y,Word tile)
  189. {
  190.     Byte *Screenad;
  191.     Byte *ArtStart;
  192.     Word Width,Height;
  193.  
  194.     if (!SmallFontPtr) {
  195.         return;
  196.     }    
  197.     x*=16;
  198.     y*=16;
  199.     Screenad = &VideoPointer[YTable[y]+x];
  200.     ArtStart = &SmallFontPtr[tile*(16*16)];
  201.     Height = 0;
  202.     do {
  203.         Width = 16;
  204.         do {
  205.             Screenad[0] = ArtStart[0];
  206.             ++Screenad;
  207.             ++ArtStart;
  208.         } while (--Width);
  209.         Screenad+=VideoWidth-16;
  210.     } while (++Height<16);
  211. }
  212.  
  213. void MakeSmallFont(void)
  214. {
  215.     Word i,j,Width,Height;
  216.     Byte *DestPtr,*ArtStart;
  217.     Byte *TempPtr;
  218.     
  219.     SmallFontPtr = AllocSomeMem(16*16*65);
  220.     if (!SmallFontPtr) {
  221.         return;
  222.     }
  223.     memset(SmallFontPtr,0,16*16*65);        /* Erase the font */
  224.     i = 0;
  225.     DestPtr = SmallFontPtr;
  226.     do {
  227.         ArtStart = &ArtData[i][0];
  228.         if (!ArtStart) {
  229.             DestPtr+=(16*16);
  230.         } else {
  231.             Height = 0;
  232.             do {
  233.                 Width = 16;
  234.                 j = Height*8;
  235.                 do {
  236.                     DestPtr[0] = ArtStart[j];
  237.                     ++DestPtr;
  238.                     j+=(WALLHEIGHT*8);
  239.                 } while (--Width);
  240.             } while (++Height<16);
  241.         }
  242.     } while (++i<64);
  243.     TempPtr = LoadAResource(MyBJFace);
  244.     memcpy(DestPtr,TempPtr,16*16);
  245.     ReleaseAResource(MyBJFace);
  246.     
  247. #if 0
  248.     TempPtr = AllocSomeMem(16*16*128);
  249.     memset(TempPtr,-1,16*16*128);
  250.     i = 0;
  251.     do {
  252.         memcpy(&TempPtr[(i+1)*256],&SmallFontPtr[(i*2)*256],256);
  253.     } while (++i<29);
  254.     i = 0;
  255.     do { 
  256.         memcpy(&TempPtr[((i*2)+90)*256],&SmallFontPtr[(i+59)*256],256);
  257.         memcpy(&TempPtr[((i*2)+91)*256],&SmallFontPtr[(i+59)*256],256);
  258.     } while (++i<4);
  259.     SaveJunk(TempPtr,256*128);
  260.     FreeSomeMem(TempPtr);
  261. #endif
  262. }
  263.  
  264. void KillSmallFont(void)
  265. {    
  266.     if (SmallFontPtr) {
  267.         FreeSomeMem(SmallFontPtr);
  268.         SmallFontPtr=0;        
  269.     }
  270. }
  271.  
  272.